package com.ruoyi.project.system.partymember.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.text.Convert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.partymember.mapper.PartyMemberMapper;
import com.ruoyi.project.system.partymember.domain.PartyMember;
import com.ruoyi.project.system.partymember.service.IPartyMemberService;

/**
 * 党员信息服务实现类
 * 
 * @author ruoyi
 * @date 2023-07-15
 */
@Service
public class PartyMemberServiceImpl implements IPartyMemberService 
{
	@Autowired
	private PartyMemberMapper partyMemberMapper;

	/**
     * 查询党员信息
     * 
     * @param id 党员信息主键
     * @return 党员信息
     */
	@Override
	public PartyMember selectPartyMemberById(Long id)
	{
		return partyMemberMapper.selectPartyMemberById(id);
	}

	/**
     * 查询党员信息列表
     * 
     * @param partyMember 党员信息
     * @return 党员信息集合
     */
	@Override
	public List<PartyMember> selectPartyMemberList(PartyMember partyMember)
	{
		return partyMemberMapper.selectPartyMemberList(partyMember);
	}
	
	/**
     * 根据用户ID查询党员信息
     *
     * @param userId 用户ID
     * @return 党员信息
     */
	@Override
	public PartyMember selectPartyMemberByUserId(Long userId)
	{
		return partyMemberMapper.selectPartyMemberByUserId(userId);
	}

	/**
     * 新增党员信息
     * 
     * @param partyMember 党员信息
     * @return 结果
     */
	@Override
	public int insertPartyMember(PartyMember partyMember)
	{
		partyMember.setCreateTime(DateUtils.getNowDate());
		return partyMemberMapper.insertPartyMember(partyMember);
	}

	/**
     * 修改党员信息
     * 
     * @param partyMember 党员信息
     * @return 结果
     */
	@Override
	public int updatePartyMember(PartyMember partyMember)
	{
		partyMember.setUpdateTime(DateUtils.getNowDate());
		return partyMemberMapper.updatePartyMember(partyMember);
	}
	/**
     * 批量删除党员信息
     * 
     * @param ids 需要删除的党员信息主键
     * @return 结果
     */
	@Override
	public int deletePartyMemberByIds(Long[] ids)
	{
		return partyMemberMapper.deletePartyMemberByIds(ids);
	}

	/**
     * 删除党员信息信息
     * 
     * @param id 党员信息主键
     * @return 结果
     */
	@Override
	public int deletePartyMemberById(Long id)
	{
		return partyMemberMapper.deletePartyMemberById(id);
	}
	
	/**
     * 校验党员编号唯一性
     * 
     * @param partyMember 党员信息
     * @return 结果
     */
	@Override
	public boolean checkPartyNoUnique(PartyMember partyMember)
	{
		Long id = StringUtils.isNull(partyMember.getId()) ? -1L : partyMember.getId();
		PartyMember info = partyMemberMapper.checkPartyNoUnique(partyMember.getPartyNo());
		if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue())
		{
			return false;
		}
		return true;
	}
}